#!/usr/bin/env bash

#By caofangkuai（http://www.caofangkuai.top/）修改自https://gist.github.com/aaronfranke/79b424226475d277d0035b7835b09c5f
#Google翻译

# 该脚本将 Godot 3 项目中的许多内容批量重命名
# 更容易将它们转换为 Godot 4。目标是做尽可能多的事情
# 此处尽可能替换，以使 Godot 产生的差异更小。

set -uo pipefail

apt install perl -y

function start(){
for file in `ls $1`
do
 if [ -d $1"/"$file ]
 then
 start $1"/"$file
 else
 echo "当前文件："$1"/"$file
 convertTo4x $1"/"$file
 fi
done
}

function convertTo4x(){
f="$1"
if [[ "$f" == *"md" ]]; then
		continue
	elif [[ "$f" == *"txt" ]]; then
		continue
	elif [[ "$f" == *"sh" ]]; then
		continue
	elif [[ "$f" == *"bash" ]]; then
		continue
	elif [[ "$f" == *".gdshader" ]]; then
		# 将“.gdshader”文件重命名为“.gdshader”。
		mv "$f" "${f%.gdshader}.gdshader"
		continue
	fi
	# 所有文件的批量操作。
	perl -i -pe 's/XR/XR/g' "$f"
	perl -i -pe 's/Node3D/Node3D/g' "$f"
	perl -i -pe 's/Node3DAgent3D/Node3DAgent3D3D/g' "$f"
	perl -i -pe 's/Node3DRegion3D/Node3DRegion3D/g' "$f"
	perl -i -pe 's/Node3DObstacle3D\b/Node3DObstacle3D/g' "$f"
	perl -i -pe 's/Node3DRegion3D/Node3DRegion3D/g' "$f"
	perl -i -pe 's/\.gdshader/\.gdshader/g' "$f"
	perl -i -pe 's/\bAnimatedSprite\b/AnimatedSprite2D/g' "$f"
	perl -i -pe 's/\bAnimationTreePlayer\b/AnimationTree/g' "$f"
	perl -i -pe 's/\bArea\b/Area3D/g' "$f"
	perl -i -pe 's/\bBakedLightmap\b/LightmapGI/g' "$f"
	perl -i -pe 's/\bBitmapFont\b/Font/g' "$f"
	perl -i -pe 's/\bBoneAttachment\b/BoneAttachment3D/g' "$f"
	perl -i -pe 's/\bBone\b/Bone3D/g' "$f"
	perl -i -pe 's/\bBoxShape\b/BoxShape3D/g' "$f"
	perl -i -pe 's/\bBulletPhysicsDirectBodyState\b/BulletPhysicsDirectBodyState3D/g' "$f"
	perl -i -pe 's/\bBulletPhysicsServer\b/BulletPhysicsServer3D/g' "$f"
	perl -i -pe 's/\bButtonList\b/MouseButton/g' "$f"
	perl -i -pe 's/\bCPUParticles\b/CPUParticles3D/g' "$f"
	perl -i -pe 's/\bCSGBox\b/CSGBox3D/g' "$f"
	perl -i -pe 's/\bCSGCombiner\b/CSGCombiner3D/g' "$f"
	perl -i -pe 's/\bCSGCylinder\b/CSGCylinder3D/g' "$f"
	perl -i -pe 's/\bCSGMesh\b/CSGMesh3D/g' "$f"
	perl -i -pe 's/\bCSGPolygon\b/CSGPolygon3D/g' "$f"
	perl -i -pe 's/\bCSGPrimitive\b/CSGPrimitive3D/g' "$f"
	perl -i -pe 's/\bCSGShape\b/CSGShape3D/g' "$f"
	perl -i -pe 's/\bCSGSphere\b/CSGSphere3D/g' "$f"
	perl -i -pe 's/\bCSGTorus\b/CSGTorus3D/g' "$f"
	perl -i -pe 's/\bCamera\b/Camera3D/g' "$f"
	perl -i -pe 's/\bCapsuleShape\b/CapsuleShape3D/g' "$f"
	perl -i -pe 's/\bClippedCamera\b/ClippedCamera3D/g' "$f"
	perl -i -pe 's/\bCollisionObject\b/CollisionObject3D/g' "$f"
	perl -i -pe 's/\bCollisionPolygon\b/CollisionPolygon3D/g' "$f"
	perl -i -pe 's/\bCollisionShape\b/CollisionShape3D/g' "$f"
	perl -i -pe 's/\bConcavePolygonShape\b/ConcavePolygonShape3D/g' "$f"
	perl -i -pe 's/\bConeTwistJoint\b/ConeTwistJoint3D/g' "$f"
	perl -i -pe 's/\bConvexPolygonShape\b/ConvexPolygonShape3D/g' "$f"
	perl -i -pe 's/\bCubeMesh\b/BoxMesh/g' "$f"
	perl -i -pe 's/\bCylinderShape\b/CylinderShape3D/g' "$f"
	perl -i -pe 's/\bDirectionalLight\b/DirectionalLight3D/g' "$f"
	perl -i -pe 's/\bDynamicFontData\b/FontData/g' "$f"
	perl -i -pe 's/\bDynamicFont\b/Font/g' "$f"
	perl -i -pe 's/\bEditorSpatialGizmo\b/EditorNode3DGizmo/g' "$f"
	perl -i -pe 's/\bGIProbe\b/VoxelGI/g' "$f"
	perl -i -pe 's/\bGeneric6DOFJoint\b/Generic6DOFJoint3D/g' "$f"
	perl -i -pe 's/\bGeometryInstance\b/GeometryInstance3D/g' "$f"
	perl -i -pe 's/\bHeightMapShape\b/HeightMapShape3D/g' "$f"
	perl -i -pe 's/\bHingeJoint\b/HingeJoint3D/g' "$f"
	perl -i -pe 's/\bIP_Unix\b/IPUnix/g' "$f"
	perl -i -pe 's/\bImmediateGeometry\b/ImmediateGeometry3D/g' "$f"
	perl -i -pe 's/\bInterpolatedCamera\b/InterpolatedCamera3D/g' "$f"
	perl -i -pe 's/\bJoint\b/Joint3D/g' "$f"
	perl -i -pe 's/\bKinematicBody2D\b/CharacterBody2D/g' "$f"
	perl -i -pe 's/\bKinematicBody\b/CharacterBody3D/g' "$f"
	perl -i -pe 's/\bKinematicCollision\b/KinematicCollision3D/g' "$f"
	perl -i -pe 's/\bLight2D\b/PointLight2D/g' "$f"
	perl -i -pe 's/\bLight\b/Light3D/g' "$f"
	perl -i -pe 's/\bListener\b/Listener3D/g' "$f"
	perl -i -pe 's/\bMODE_OPEN_ANY\b/FILE_MODE_OPEN_ANY/g' "$f"
	perl -i -pe 's/\bMODE_OPEN_DIR\b/FILE_MODE_OPEN_DIR/g' "$f"
	perl -i -pe 's/\bMODE_OPEN_FILES\b/FILE_MODE_OPEN_FILE/g' "$f"
	perl -i -pe 's/\bMODE_OPEN_FILE\b/FILE_MODE_OPEN_FILE/g' "$f"
	perl -i -pe 's/\bMODE_SAVE_FILE\b/FILE_MODE_SAVE_FILE/g' "$f"
	perl -i -pe 's/\bMeshInstance\b/MeshInstance3D/g' "$f"
	perl -i -pe 's/\bMultiMeshInstance\b/MultiMeshInstance3D/g' "$f"
	perl -i -pe 's/\bNode2DServer\b/Node3DServer2D/g' "$f"
	perl -i -pe 's/\bNode3DServer\b/Node3DServer3D/g' "$f"
	perl -i -pe 's/\bOmniLight\b/OmniLight3D/g' "$f"
	perl -i -pe 's/\bPAUSE_MODE_INHERIT\b/PROCESS_MODE_INHERIT/g' "$f"
	perl -i -pe 's/\bPAUSE_MODE_PROCESS\b/PROCESS_MODE_ALWAYS/g' "$f"
	perl -i -pe 's/\bPAUSE_MODE_STOP\b/PROCESS_MODE_PAUSABLE/g' "$f"
	perl -i -pe 's/\bPHashTranslation\b/OptimizedTranslation/g' "$f"
	perl -i -pe 's/\bPanoramaSky\b/PanoramaSkyMaterial/g' "$f"
	perl -i -pe 's/\bParticles2D\b/GPUParticles2D/g' "$f"
	perl -i -pe 's/\bParticles\b/GPUParticles3D/g' "$f"
	perl -i -pe 's/\bPathFollow\b/PathFollow3D/g' "$f"
	perl -i -pe 's/\bPath\b/Path3D/g' "$f"
	perl -i -pe 's/\bPhysicalBone\b/PhysicalBone3D/g' "$f"
	perl -i -pe 's/\bPhysics2DDirectBodyStateSW\b/PhysicsDirectBodyState2DSW/g' "$f"
	perl -i -pe 's/\bPhysics2DDirectBodyState\b/PhysicsDirectBodyState2D/g' "$f"
	perl -i -pe 's/\bPhysics2DDirectSpaceState\b/PhysicsDirectSpaceState2D/g' "$f"
	perl -i -pe 's/\bPhysics2DServer\b/PhysicsServer2D/g' "$f"
	perl -i -pe 's/\bPhysics2DShapeQueryParameters\b/PhysicsShapeQueryParameters2D/g' "$f"
	perl -i -pe 's/\bPhysics2DShapeQueryResult\b/PhysicsShapeQueryResult2D/g' "$f"
	perl -i -pe 's/\bPhysics2DTestMotionResult\b/PhysicsTestMotionResult2D/g' "$f"
	perl -i -pe 's/\bPhysicsBody\b/PhysicsBody3D/g' "$f"
	perl -i -pe 's/\bPhysicsDirectBodyState\b/PhysicsDirectBodyState3D/g' "$f"
	perl -i -pe 's/\bPhysicsDirectSpaceState\b/PhysicsDirectSpaceState3D/g' "$f"
	perl -i -pe 's/\bPhysicsServer\b/PhysicsServer3D/g' "$f"
	perl -i -pe 's/\bPhysicsShapeQueryParameters\b/PhysicsShapeQueryParameters3D/g' "$f"
	perl -i -pe 's/\bPhysicsShapeQueryResult\b/PhysicsShapeQueryResult3D/g' "$f"
	perl -i -pe 's/\bPinJoint\b/PinJoint3D/g' "$f"
	perl -i -pe 's/\bPlaneShape\b/WorldMarginShape3D/g' "$f"
	perl -i -pe 's/\bPoolByteArray\b/PackedByteArray/g' "$f"
	perl -i -pe 's/\bPoolColorArray\b/PackedColorArray/g' "$f"
	perl -i -pe 's/\bPoolIntArray\b/PackedInt32Array/g' "$f"
	perl -i -pe 's/\bPoolRealArray\b/PackedFloat32Array/g' "$f"
	perl -i -pe 's/\bPoolStringArray\b/PackedStringArray/g' "$f"
	perl -i -pe 's/\bPoolVector2Array\b/PackedVector2Array/g' "$f"
	perl -i -pe 's/\bPoolVector3Array\b/PackedVector3Array/g' "$f"
	perl -i -pe 's/\bPopupDialog\b/Popup/g' "$f"
	perl -i -pe 's/\bProceduralSky\b/Sky/g' "$f"
	perl -i -pe 's/\bProximityGroup\b/ProximityGroup3D/g' "$f"
	perl -i -pe 's/\bQuat\b/Quaternion/g' "$f"
	perl -i -pe 's/\bRayCast\b/RayCast3D/g' "$f"
	perl -i -pe 's/\bRayShape\b/RayShape3D/g' "$f"
	perl -i -pe 's/\bRemoteTransform\b/RemoteTransform3D/g' "$f"
	perl -i -pe 's/\bRigidBody\b/RigidDynamicBody3D/g' "$f"
	perl -i -pe 's/\bShape\b/Shape3D/g' "$f"
	perl -i -pe 's/\bShortCut\b/Shortcut/g' "$f"
	perl -i -pe 's/\bSkeletonIK\b/SkeletonIK3D/g' "$f"
	perl -i -pe 's/\bSkeleton\b/Skeleton3D/g' "$f"
	perl -i -pe 's/\bSliderJoint\b/SliderJoint3D/g' "$f"
	perl -i -pe 's/\bSoftBody\b/SoftBody3D/g' "$f"
	perl -i -pe 's/\bSpatialMaterial\b/StandardMaterial3D/g' "$f"
	perl -i -pe 's/\bSpatialVelocityTracker\b/VelocityTracker3D/g' "$f"
	perl -i -pe 's/\bSpatial\b/Node3D/g' "$f"
	perl -i -pe 's/\bSphereShape\b/SphereShape3D/g' "$f"
	perl -i -pe 's/\bSpotLight\b/SpotLight3D/g' "$f"
	perl -i -pe 's/\bSpringArm\b/SpringArm3D/g' "$f"
	perl -i -pe 's/\bSprite\b/Sprite2D/g' "$f"
	perl -i -pe 's/\bStaticBody\b/StaticBody3D/g' "$f"
	perl -i -pe 's/\bStreamTexture\b/StreamTexture2D/g' "$f"
	perl -i -pe 's/\bTCP_Server\b/TCPServer/g' "$f"
	perl -i -pe 's/\bTYPE_QUAT\b/TYPE_QUATERNION/g' "$f"
	perl -i -pe 's/\bTYPE_REAL\b/TYPE_FLOAT/g' "$f"
	perl -i -pe 's/\bTextureArray\b/Texture2DArray/g' "$f"
	perl -i -pe 's/\bTextureProgress\b/TextureProgressBar/g' "$f"
	perl -i -pe 's/\bTexture\b/Texture2D/g' "$f"
	perl -i -pe 's/\bToolButton\b/Button/g' "$f"
	perl -i -pe 's/\bTransform\b/Transform3D/g' "$f"
	perl -i -pe 's/\bVehicleBody\b/VehicleBody3D/g' "$f"
	perl -i -pe 's/\bVehicleWheel\b/VehicleWheel3D/g' "$f"
	perl -i -pe 's/\bViewportContainer\b/SubViewportContainer/g' "$f"
	perl -i -pe 's/\bViewport\b/SubViewport/g' "$f"
	perl -i -pe 's/\bVisibilityEnabler2D\b/VisibleOnScreenEnabler2D/g' "$f"
	perl -i -pe 's/\bVisibilityEnabler\b/VisibleOnScreenEnabler3D/g' "$f"
	perl -i -pe 's/\bVisibilityNotifier2D\b/VisibleOnScreenNotifier2D/g' "$f"
	perl -i -pe 's/\bVisibilityNotifier\b/VisibleOnScreenNotifier3D/g' "$f"
	perl -i -pe 's/\bVisualInstance\b/VisualInstance3D/g' "$f"
	perl -i -pe 's/\bVisualServer\b/RenderingServer/g' "$f"
	perl -i -pe 's/\bWorld\b/World3D/g' "$f"
	perl -i -pe 's/\bXRAnchor\b/XRAnchor3D/g' "$f"
	perl -i -pe 's/\bXRController\b/XRController3D/g' "$f"
	perl -i -pe 's/\bXROrigin\b/XROrigin3D/g' "$f"
	perl -i -pe 's/\bYSort\b/Node2D/g' "$f"
	perl -i -pe 's/as_normal_map/as_normal_map/g' "$f"
	perl -i -pe 's/button_releasedd/button_releaseddd/g' "$f"
	perl -i -pe 's/double_click/double_click/g' "$f"
	perl -i -pe 's/is_valid_int/is_valid_int/g' "$f"
	perl -i -pe 's/lerp/lerp/g' "$f"
	perl -i -pe 's/process_mode = 3/process_mode = 3/g' "$f"
	perl -i -pe 's/process_mode/process_mode/g' "$f"
	perl -i -pe 's/popup_centered_clamped/popup_centered_clamped/g' "$f"
	perl -i -pe 's/tab_closedd/tab_closeddd/g' "$f"
	perl -i -pe 's/tab_hovereded/tab_hoverededed/g' "$f"
	perl -i -pe 's/top_level/top_level/g' "$f"
	perl -i -pe 's/far/far/g' "$f"
	perl -i -pe 's/near/near/g' "$f"

	perl -i -pe 's/2D/2D/g' "$f"

	if [[ "$f" == *"tscn" ]]; then
		# 场景的批量操作。
		perl -i -pe 's/(Color|Vector[23]|Rect2|AABB|Basis|Plane|Quaternion|Transform3D[23]D|Packed[^(]*)\( ([^)]*) \)/\1\(\2\)/g' "$f"
		perl -i -pe 's/\:translation/\:position/g' "$f"
		perl -i -pe 's/\[ /\[/g' "$f"
		perl -i -pe 's/ \]/\]/g' "$f"
		perl -i -pe 's/margin_/offset_/g' "$f"
		perl -i -pe 's/material\/0 \= /surface_material_override\/0 \= /g' "$f"
	elif [[ "$f" == *"csproj" ]]; then
		# csproj 文件的批量操作。
		perl -i -pe 's/Godot\.NET\.Sdk\/3\.3\.0/Godot\.NET\.Sdk\/4\.0\.0\-dev5/g' "$f"
	elif [[ "$f" == *"cs" ]]; then
		# C# 文件的批量操作。
		perl -i -pe 's/GetPositionInParent/GetIndex/g' "$f"
		perl -i -pe 's/Instance\(/Instantiate\(/g' "$f"
		perl -i -pe 's/Texture2D\ \=/Texture2D\ \=/g' "$f"
		perl -i -pe 's/Transform3D\ \=/Transform3D\ \=/g' "$f"
		perl -i -pe 's/Transform3D\;/Transform3D\;/g' "$f"
		perl -i -pe 's/Translation\ \=/Position\ \=/g' "$f"
		perl -i -pe 's/Translation\;/Position\;/g' "$f"
		perl -i -pe 's/public\ class/public\ partial\ class/g' "$f"
	elif [[ "$f" == *"gd" ]]; then
		# 首先保留这些。
		perl -i -pe 's/camera_translation/camera_position/g' "$f"
		perl -i -pe 's/parent_translation/parent_position/g' "$f"
		perl -i -pe 's/\*\ ([^(^*^\s]+)\.xform\(([^)]+)\)/* \(\1 * \2\)/g' "$f"
		# GDScript 文件的批量操作。
		perl -i -pe 's/(\t+)\./\1super\./g' "$f"
		perl -i -pe 's/(\t+)return \./\1return super\./g' "$f"
		perl -i -pe 's/(\t+)var (.+) = parse_json\((.+)\)/\1var json = JSON\.new()\n\1json\.parse(\3)\n\1var \2 = json\.get_data\(\)/g' "$f"
		perl -i -pe 's/= (.*)\.xform_inv\((.*)\)\./= \(\2 * \1\)\./g' "$f"
		perl -i -pe 's/= (.*)\.xform_inv\((.*)\)/= \2 * \1/g' "$f"
		perl -i -pe 's/Input\.get_action_strength\("([^"]+)"\) - Input\.get_action_strength\("([^"]+)"\)/Input.get_axis(&"\2", &"\1")/g' "$f"
		perl -i -pe 's/Vector3(.*) # TODO: Vector3i/Vector3i\1/g' "$f"
		perl -i -pe 's/\ translation/\ position/g' "$f"
		perl -i -pe 's/\(translation/\(position/g' "$f"
		perl -i -pe 's/\.empty\(/\.is_empty\(/g' "$f"
		perl -i -pe 's/\.instance\(/\.instantiate\(/g' "$f"
		perl -i -pe 's/\.invert\(/\.reverse\(/g' "$f"
		perl -i -pe 's/\.translation/\.position/g' "$f"
		perl -i -pe 's/\.xform\(/\ * \(/g' "$f"
		perl -i -pe 's/\bBUTTON_/MOUSE_BUTTON_/g' "$f"
		perl -i -pe 's/\bReference\b/RefCounted/g' "$f"
		perl -i -pe 's/^export\(([^)]*)\) var ([a-zA-Z0-9_]*)/\@export var \2: \1/g' "$f"
		perl -i -pe 's/^\@export var ([^:]*): ([^:^=]*):\=/\@export var \1 :\=/g' "$f"
		perl -i -pe 's/connect\("([^"]+)", ([^,]+), "([^"]+)"/connect\(&"\1", \2\.\3/g' "$f"
		perl -i -pe 's/Engine\.get_idle_frames/Engine.get_process_frames/g' "$f"
		perl -i -pe 's/export\(String, File, ([^)]*)\)/@export_file\(\1\)/g' "$f"
		perl -i -pe 's/export\(float, ([^,]*), ([^,]*)\) var ([a-zA-Z0-9_]*)(: float)?/@export_range\(\1, \2\) var \3: float/g' "$f"
		perl -i -pe 's/get_camera\(\)/get_camera_3d()/g' "$f"
		perl -i -pe 's/get_node\(\@?\"/get_node\(\^\"/g' "$f"
		perl -i -pe 's/get_position_in_parent/get_index/g' "$f"
		perl -i -pe 's/get_rotation_quat/get_rotation_quaternion/g' "$f"
		perl -i -pe 's/get_world\(\)/get_world_3d()/g' "$f"
		perl -i -pe 's/if !/if not /g' "$f"
		perl -i -pe 's/(\t+)linear_velocity\ \=\ move_and_slide\(linear_velocity([^)]*)(\)+)/\1# TODO: This information should be set to the CharacterBody properties instead of arguments: \2\n\1move_and_slide()/g' "$f"
		perl -i -pe 's/(\t+)linear_velocity\ \=\ move_and_slide_with_snap\(linear_velocity([^)]*)(\)+)/\1# TODO: This information should be set to the CharacterBody properties instead of arguments: snap\2\n\1move_and_slide()/g' "$f"
		perl -i -pe 's/rand_range/randf_range/g' "$f"
		perl -i -pe 's/sort_custom\(([^)]*), "([^"]*)"\)/sort_custom(Callable(\1, &"\2"))/g' "$f"
		perl -i -pe 's/stepify/snapped/g' "$f"
		perl -i -pe 's/to_json\(/JSON\.new\(\)\.stringify\(/g' "$f"
		perl -i -pe 's/track_remove_key_at_position/track_remove_key_at_time/g' "$f"
		perl -i -pe 's/translation\ \+\=/position\ \+\=/g' "$f"
		perl -i -pe 's/translation\ \=/position\ \=/g' "$f"
		perl -i -pe 's/(\t+)_*velocity\ \=\ move_and_slide\(_*velocity([^)]*)(\)+)/\1# TODO: This information should be set to the CharacterBody properties instead of arguments: \2\n\1# TODO: Rename velocity to linear_velocity in the rest of the script.\n\1move_and_slide()/g' "$f"
		perl -i -pe 's/(\t+)_*velocity\ \=\ move_and_slide_with_snap\(_*velocity([^)]*)(\)+)/\1# TODO: This information should be set to the CharacterBody properties instead of arguments: snap\2\n\1# TODO: Rename velocity to linear_velocity in the rest of the script.\n\1move_and_slide()/g' "$f"
		perl -i -pe 's/yield\(get_tree\(\)\,\ \"idle_frame\"\)/await\ get_tree\(\)\.process_frame/g' "$f"
		# 将 'yield($MessageTimer, "timeout")' 等转换为 'await $MessageTimer.timeout'
		perl -i -pe 's/yield\((.*), "(.*)"\)/await\ \1\.\2/g' "$f"
		# 将颜色常量大写，例如“Color.white”->“Color.WHITE”
		perl -i -pe 's/Color\.([a-z]+)/Color\.\U\1/g' "$f"
		# 将 setgets 转换为 4.x 语法，但这无法通过正则表达式完全完成，因此请保留 TODO。
		perl -i -pe 's/ setget ([^,\n]*), ([^\n]*)/\:\n\tget\:\n\t\t# TODO: Manually copy the code from this method.\n\t\treturn \2\(\)\n\tset\(value\)\:\n\t\t# TODO: Manually copy the code from this method.\n\t\t\1\(value\)/g' "$f"
		perl -i -pe 's/ setget ([^,\n]*)/\:\n\tset\(value\)\:\n\t\t# TODO: Manually copy the code from this method.\n\t\t\1\(value\)/g' "$f"
		# 把这些放在最后。
		perl -i -pe 's/(\t+)([^\t]+) = move_and_slide(_with_snap)*/\1# TODO: This information should be set to the CharacterBody properties instead of arguments.\n\1move_and_slide/g' "$f"
		perl -i -pe 's/(\t+)([^\t]+)move_and_slide(_with_snap)*/\1# TODO: This information should be set to the CharacterBody properties instead of arguments.\n\1\2move_and_slide/g' "$f"
		perl -i -pe 's/^export/\@export/g' "$f"
		perl -i -pe 's/^onready/\@onready/g' "$f"
		perl -i -pe 's/^tool/\@tool/g' "$f"
	elif [[ "$f" == *"import" ]]; then
		# 导入文件的批量操作。
		perl -i -pe 's/res\:\/\/\.import/res\:\/\/\.godot\/imported/g' "$f"
		perl -i -pe 's/\[ /\[/g' "$f"
		perl -i -pe 's/ \]/\]/g' "$f"
		# 将 Godot 3 导入设置批量替换为 Godot 4 等效项。
		perl -0 -i -pe 's/compress\/hdr_mode\=0\ncompress\/bptc_ldr\=0\ncompress\/normal_map\=0\nflags\/repeat\=0\nflags\/filter\=true\nflags\/mipmaps\=false\nflags\/anisotropic\=false\nflags\/srgb\=2\nprocess\/fix_alpha_border\=true\nprocess\/premult_alpha\=false\nprocess\/HDR_as_SRGB\=false\nprocess\/invert_color\=false(process\/normal_map_invert_y\=false\n)*\nstream\=false\nsize_limit\=0\ndetect_3d\=true/compress\/hdr_compression\=1\ncompress\/bptc_ldr\=0\ncompress\/normal_map\=0\ncompress\/channel_pack\=0\ncompress\/streamed\=false\nmipmaps\/generate\=false\nmipmaps\/limit\=\-1\nroughness\/mode\=0\nroughness\/src_normal\=\"\"\nprocess\/fix_alpha_border\=true\nprocess\/premult_alpha\=false\nprocess\/normal_map_invert_y\=false\nprocess\/HDR_as_SRGB\=false\nprocess\/size_limit\=0\ndetect_3d\/compress_to\=1/g' "$f"
		perl -0 -i -pe 's/compress\/hdr_mode\=0\ncompress\/bptc_ldr\=0\ncompress\/normal_map\=0\nflags\/repeat\=0\nflags\/filter\=false\nflags\/mipmaps\=false\nflags\/anisotropic\=false\nflags\/srgb\=2\nprocess\/fix_alpha_border\=true\nprocess\/premult_alpha\=false\nprocess\/HDR_as_SRGB\=false\nprocess\/invert_color\=false(process\/normal_map_invert_y\=false\n)*\nstream\=false\nsize_limit\=0\ndetect_3d\=true/compress\/hdr_compression\=1\ncompress\/bptc_ldr\=0\ncompress\/normal_map\=0\ncompress\/channel_pack\=0\ncompress\/streamed\=false\nmipmaps\/generate\=false\nmipmaps\/limit\=\-1\nroughness\/mode\=0\nroughness\/src_normal\=""\nprocess\/fix_alpha_border\=true\nprocess\/premult_alpha\=false\nprocess\/normal_map_invert_y\=false\nprocess\/HDR_as_SRGB\=false\nprocess\/size_limit\=0\ndetect_3d\/compress_to\=1/g' "$f"
		perl -0 -i -pe 's/compress\/hdr_mode\=0\ncompress\/bptc_ldr\=0\ncompress\/normal_map\=0\nflags\/repeat\=0\nflags\/filter\=false\nflags\/mipmaps\=false\nflags\/anisotropic\=false\nflags\/srgb\=2\nprocess\/fix_alpha_border\=true\nprocess\/premult_alpha\=false\nprocess\/HDR_as_SRGB\=false\nprocess\/invert_color\=false(process\/normal_map_invert_y\=false\n)*\nstream\=false\nsize_limit\=0\ndetect_3d\=false/compress\/hdr_compression\=1\ncompress\/bptc_ldr\=0\ncompress\/normal_map\=0\ncompress\/channel_pack\=0\ncompress\/streamed\=false\nmipmaps\/generate\=false\nmipmaps\/limit\=\-1\nroughness\/mode\=0\nroughness\/src_normal\=""\nprocess\/fix_alpha_border\=true\nprocess\/premult_alpha\=false\nprocess\/normal_map_invert_y\=false\nprocess\/HDR_as_SRGB\=false\nprocess\/size_limit\=0\ndetect_3d\/compress_to\=1/g' "$f"
		#perl -0 -i -pe 's///g' "$f"
	elif [[ "$f" == *"project.godot" ]]; then
		#project.godot 文件的批量操作。
		perl -i -pe 's/(Color|Vector[23]|Rect2|AABB|Basis|Plane|Quaternion|Transform3D[23]D|Packed[^(]*)\( ([^)]*) \)/\1\(\2\)/g' "$f"
		perl -i -pe 's/\"class\"\: \"/\"class\"\: \&\"/g' "$f"
		perl -i -pe 's/\"language\"\: \"/\"language\"\: \&\"/g' "$f"
		perl -i -pe 's/\[ /\[/g' "$f"
		perl -i -pe 's/ \]/\]/g' "$f"
		# 将 3.x 样式输入批量替换为 4.x 样式输入。
		perl -i -pe 's/Object\(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":(\d+),("physical_scancode":0,)*"unicode":0,"echo":false,"script":null\)/Object\(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"store_command":true,"alt_pressed":false,"shift_pressed":false,"meta_pressed":false,"command_pressed":false,"pressed":false,"keycode":\1,"physical_keycode":0,"unicode":0,"echo":false,"script":null\)/g' "$f"
		perl -i -pe 's/Object\(InputEventMouseButton,"resource_local_to_scene"\:false,"resource_name"\:"","device"\:0,"alt"\:false,"shift"\:false,"control"\:false,"meta"\:false,"command"\:false,"button_mask"\:0,"position"\:Vector2\(0, 0\),"global_position"\:Vector2\(0, 0\),"factor"\:1\.0,"button_index"\:(\d+),"pressed"\:false,"double_click"\:([a-z]+),"script"\:null\)/Object\(InputEventMouseButton,"resource_local_to_scene"\:false,"resource_name"\:"","device"\:0,"window_id"\:0,"store_command"\:true,"alt_pressed"\:false,"shift_pressed"\:false,"meta_pressed"\:false,"command_pressed"\:false,"button_mask"\:0,"position"\:Vector2\(0, 0\),"global_position"\:Vector2\(0, 0\),"factor"\:1\.0,"button_index"\:\1,"pressed"\:false,"double_click"\:\2,"script"\:null\)/g' "$f"
	fi
}

start "$1"